import requests
import bs4
from bs4 import BeautifulSoup
url='https://cn.bing.com/images/search?q=%e5%9f%8e%e5%b8%82&qs=n&form=QBIRMH&sp=-1&pq=%e5%9f%8e%e5%b8%82&sc=8-2&cvid=FD10A3ED08A140AE848AC42AA242B47C&first=1&tsc=ImageHoverTitle'
res=requests.get(url)
#print(res)
res.encoding='utf-8'
#print(res.text)
soup=BeautifulSoup(res.text,'html.parser')
#print(soup)
tags=soup.find_all('div',{'class':'mimg'})
#print(tags)
n=1
for z in range(1,16):
        for i in tags:
        #print(i['src'])
        #a=i['src']
        #if '.png' in a:
        #        with open(str(n)+'.png','wb') as f:
        #                b=requests.get(url+a) #输出图片地址
        #                c.write(b.content)
        #                print('图片'+str(n)+'ok')
        #                n=n+1
                a=i.find('img')#发现只要img标签里的字
                b=a['src'] 
        #url+b完整的图片地址
                with open('图片'+str(n)+'.jpg','wb') as f:
                        c=requests.get(url+b) #输出图片地址
                        f.write(c.content)
                        print('图片'+str(n)+'ok')
                        n=n+1
